package com.core;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


public abstract class ContentFetcher {

	protected URL url = null;	
	
	
	public ContentFetcher(URL url){
		this.url = url;
	}
	
	/**
	 * the key should indicating who is fetched for
	 * @return
	 */
	public abstract UserRequest getUserRequest();
	
	/**
	 * if there is a number indicating which number of item should be started with
	 * return this one.
	 * @return
	 */
	public abstract int getStart();
	
	/**
	 * set the start value
	 */
	public abstract void setStart(int s);
	/**
	 * 
	 * @return number of items fetched
	 * @throws IOException
	 */
	public abstract int loadContent() throws IOException ;

	public boolean equals(Object obj) {
		if(obj== null){
			return false;
		}
		if(getUserRequest()==null&&((ContentFetcher)obj).getUserRequest()==null){
			return true;
		}
		if(getUserRequest()==null&&((ContentFetcher)obj).getUserRequest()!=null){
			return false;
		}		
		return this.getClass().getName().equals(obj.getClass().getName()) && 
		( getUserRequest().equals(((ContentFetcher)obj).getUserRequest()) );
	}
	
	public String toString() {
		return getUserRequest()+this.getClass().getName();
	}
	
	public int hashCode() {
		return toString().hashCode();
	}

	public abstract int calcStart(int numberOfLoadedItems) ;
}
